package miniproj.models.room;

import javax.xml.bind.annotation.XmlElement;

import miniproj.models.building.Building;

/**
 * This class represents the ID of a room
 * 
 * @author Baptiste Viale
 * 
 */
public class RoomId implements java.io.Serializable {

	private static final long serialVersionUID = -5975148667449969889L;

	@XmlElement
	private Building building;

	@XmlElement
	private int floor;

	@XmlElement
	private int numRoom;

	/**
	 * Instantiates a new room id. (JavaBeans)
	 */
	public RoomId() {
	}

	/**
	 * Instantiates a new room id.
	 * 
	 * @param building
	 *            the building in which the room is located
	 * @param floor
	 *            the floor
	 * @param numRoom
	 *            the number of the room
	 */
	public RoomId(Building building, int floor, int numRoom) {
		this.building = building;
		this.floor = floor;
		this.numRoom = numRoom;
	}

	/**
	 * Returns the building of this room
	 * 
	 * @return the building in which the room is located
	 */
	public Building getBuilding() {
		return this.building;
	}

	/**
	 * Returns the floor of this room
	 * 
	 * @return the floor
	 */
	public int getFloor() {
		return this.floor;
	}

	/**
	 * Returns the number of this room
	 * 
	 * @return the number of this room
	 */
	public int getNumRoom() {
		return this.numRoom;
	}

	@Override
	public String toString() {
		return this.building.getName().substring(0, 1).toUpperCase()
				+ (this.floor >= 0 ? "+" + this.floor : this.floor)
				+ (this.numRoom >= 10 ? this.numRoom : "0" + this.numRoom);
	}

	@Override
	public boolean equals(Object roomId) {
		return roomId.toString().equals(this.toString());
	}

}
